package com.copa.l1;

/**
 * @author copa
 * @createDate 2022-04-25 20:55
 * @function 暴力法 O(n^2)
 */
public class Test1 {
    public int[] twoSum(int[] nums, int target) {
        // 双重循环，第一个指针在第一层，第二个指针永远在第一个指针的后面
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (nums[i] + nums[j] == target) {
                    return new int[]{i, j};
                }
            }
        }
        return null;
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        int[] result = new Test1().twoSum(nums, target);
        for (int i : result) {
            System.out.println(i);
        }
    }
}
